package com.ruoyi.biz.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.biz.demo.domain.BizPerson;
import com.ruoyi.biz.demo.service.IBizPersonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业人员Controller
 *
 * @author Fei.Cong
 * @date 2024-06-05
 */
@RestController
@RequestMapping("/demo/person")
public class BizPersonController extends BaseController {

    @Autowired
    private IBizPersonService bizPersonService;

    /**
     * 查询企业人员列表
     */
    @PreAuthorize("@ss.hasPermi('demo:person:list')")
    @GetMapping("/list")
    public AjaxResult list(BizPerson bizPerson) {
        LambdaQueryWrapper<BizPerson> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return success(bizPersonService.list(lambdaQueryWrapper));
    }

    /**
     * 分页查询企业人员列表
     */
    @PreAuthorize("@ss.hasPermi('demo:person:list')")
    @GetMapping("/page")
    public TableDataInfo page(BizPerson bizPerson) {
        return getDataTable(bizPersonService.pageList(bizPerson, startPage()));
    }

    /**
     * 导出企业人员列表
     */
    @PreAuthorize("@ss.hasPermi('demo:person:export')")
    @Log(title = "企业人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPerson bizPerson) {
        List<BizPerson> list = bizPersonService.queryList(bizPerson);
        ExcelUtil<BizPerson> util = new ExcelUtil<BizPerson>(BizPerson.class);
        util.exportExcel(response, list, "企业人员数据");
    }

    /**
     * 获取企业人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('demo:person:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizPersonService.getById(id));
    }

    /**
     * 新增企业人员
     */
    @PreAuthorize("@ss.hasPermi('demo:person:add')")
    @Log(title = "企业人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPerson bizPerson) {
        return toAjax(bizPersonService.save(bizPerson));
    }

    /**
     * 修改企业人员
     */
    @PreAuthorize("@ss.hasPermi('demo:person:edit')")
    @Log(title = "企业人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPerson bizPerson) {
        return toAjax(bizPersonService.updateById(bizPerson));
    }

    /**
     * 删除企业人员
     */
    @PreAuthorize("@ss.hasPermi('demo:person:remove')")
    @Log(title = "企业人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(bizPersonService.removeBatchByIds(ids));
    }
}
